import Vue from 'vue'
import App from './App'
import store from "./store/index.js"
import tools from "./common/utils/tools.js"
import uView from "uview-ui";
import api from './common/request/index.js'
Vue.use(uView);
Vue.prototype.$store = store;
Vue.prototype.$tools = tools;
Vue.prototype.$api = api;
// 页面跳转
Vue.prototype.$navigateTo = function(urlValue) {
	uni.navigateTo({
		url: urlValue
	})
}

// 获取dom（节点）信息
Vue.prototype.$getDom = function(name) {
    // #ifdef MP-WEIXIN 
	return uni.createSelectorQuery().in(this).select(name).boundingClientRect()
    // #endif
    // #ifdef MP-ALIPAY
    return my.createSelectorQuery().select(name).boundingClientRect()
    // #endif
}


// 获取同名dom（节点）信息
Vue.prototype.$getDomAll = function(name) {
    // #ifdef MP-WEIXIN
    return uni.createSelectorQuery().in(this).select(name).boundingClientRect()
    // #endif
    // #ifdef MP-ALIPAY
    return my.createSelectorQuery().selectAll(name).boundingClientRect()
    // #endif
}
// 校验表单
Vue.prototype.verification= function(v_data, form_rule) {
    var breaked = false;
    var error_message = null;
    for(var key in form_rule) {
        var rules = form_rule[key].rules;
        var type = form_rule[key].type;
        if(type == "form_data") {
            var l_length = rules.length;
            for(let k = 0;  k < l_length; k++ ) {
              if(rules[k].rule.test(v_data[key]) != rules[k].v_res) {
					breaked = true;
                    error_message = rules[k].message;
					uni.showToast({
						title: error_message,
						icon: 'none',
						duration: 2000
					})
                    break ;
              }
            }
        } else if(type == 'img') {
            if(v_data[key].length == 0) {
                    breaked = true;
                    error_message = form_rule[key].message;
					uni.showToast({
						title: error_message,
						icon: 'none',
						duration: 2000
					})
                    break ;
            }
        }
        if(breaked) {break;}
    }
    if(breaked) {
        return {status: false,  message: error_message};
    } else {
        return {status: true, message: null}
    }
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()
